package dev.alm.meituanservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dev.alm.meituanservice.common.Result;
import dev.alm.meituanservice.entity.Food;
import dev.alm.meituanservice.service.FoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("food")
@CrossOrigin
public class FoodController {

    @Resource
    private FoodService foodService;

    @PostMapping("add")
    public Result add(@RequestBody Food food) {
        Food food1 = foodService.addFood(food);
        Result r = new Result();

        if (food1 == null) {
            r.setCode("500");
            r.setMessage("fail");
            return r;
        }
        r.setCode("200");
        r.setMessage("success");
        r.setData(food1);
        return r;
    }

    @PostMapping("listByCategoryCode")
    public Result listByCategoryCode(@RequestBody Food food) {
        String categoryCode = food.getCategoryCode();
        List<Food> list = foodService.getFoodListByCategoryCode(categoryCode);
        Result r = new Result();
        r.setCode("200");
        r.setMessage("success");
        r.setData(list);
        return r;
    }

    @PostMapping("listAll")
    public Result listAll() {
        List<Food> foodList = foodService.getFoodList();
        Result r = new Result();
        r.setCode("200");
        r.setMessage("success");
        r.setData(foodList);
        return r;
    }

}
